package com.androidx.p013lv.mine.activity;

import android.content.Context;
import android.text.TextUtils;
import androidx.exifinterface.media.ExifInterface;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.android.arouter.utils.Consts;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.UserInfo;
import com.androidx.p013lv.base.dialog.DialogLoading;
import com.androidx.p013lv.base.glide.GlideUtils;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.utils.DataCleanManager;
import com.androidx.p013lv.base.utils.DownloadFileUtils;
import com.androidx.p013lv.base.utils.PackageUtils;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.mine.C1207R;
import com.androidx.p013lv.mine.bean.DownLoadBean;
import com.androidx.p013lv.mine.bean.VersionBean;
import com.androidx.p013lv.mine.databinding.ActivitySettingLayoutBinding;
import com.androidx.p013lv.mine.dialog.DialogUpdate;
import com.androidx.p013lv.mine.model.VersionUpdateModel;
import com.gyf.immersionbar.ImmersionBar;
import com.lzy.okgo.model.Progress;
import java.io.File;
import p023io.reactivex.Observable;
import p023io.reactivex.ObservableEmitter;
import p023io.reactivex.ObservableOnSubscribe;
import p023io.reactivex.android.schedulers.AndroidSchedulers;
import p023io.reactivex.disposables.CompositeDisposable;
import p023io.reactivex.functions.Consumer;
import p023io.reactivex.schedulers.Schedulers;

/* renamed from: com.androidx.lv.mine.activity.SettingActivity */
public class SettingActivity extends BaseActivity<ActivitySettingLayoutBinding> implements DialogUpdate.VersionUpdateInterface {
    private CompositeDisposable compositeDisposable = new CompositeDisposable();
    DialogLoading dialog;
    private DialogUpdate dialogUpdate;
    private String downLoadUrl;
    VersionUpdateModel model;
    private UserInfo userInfo;
    private VersionBean versionBean;

    @Override // com.androidx.p013lv.mine.dialog.DialogUpdate.VersionUpdateInterface
    public void dismissDialog() {
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((ActivitySettingLayoutBinding) this.binding).toolbar).init();
    }

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return C1207R.C1212layout.activity_setting_layout;
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        ((ActivitySettingLayoutBinding) this.binding).setClick(new OnClick());
        ((ActivitySettingLayoutBinding) this.binding).setVersion(PackageUtils.getVersionName(this));
        this.compositeDisposable.add(Observable.create(new ObservableOnSubscribe<String>() {
            /* class com.androidx.p013lv.mine.activity.SettingActivity.C12682 */

            @Override // p023io.reactivex.ObservableOnSubscribe
            public void subscribe(ObservableEmitter<String> observableEmitter) throws Exception {
                observableEmitter.onNext(DataCleanManager.getTotalCacheSize(SettingActivity.this));
            }
        }).subscribeOn(Schedulers.m1118io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<String>() {
            /* class com.androidx.p013lv.mine.activity.SettingActivity.C12671 */

            public void accept(String str) throws Exception {
                ((ActivitySettingLayoutBinding) SettingActivity.this.binding).setCacheSize(str);
                if (SettingActivity.this.compositeDisposable != null) {
                    SettingActivity.this.compositeDisposable.dispose();
                }
            }
        }));
        update();
    }

    /* access modifiers changed from: protected */
    @Override // androidx.fragment.app.FragmentActivity
    public void onResume() {
        super.onResume();
        this.userInfo = SpUtils.getInstance().getUserInfo();
        ((ActivitySettingLayoutBinding) this.binding).setUserInfo(this.userInfo);
    }

    /* access modifiers changed from: package-private */
    public void update() {
        VersionUpdateModel versionUpdateModel = (VersionUpdateModel) new ViewModelProvider(this).get(VersionUpdateModel.class);
        this.model = versionUpdateModel;
        versionUpdateModel.getVersionDate().observe(this, new Observer<BaseRes<VersionBean>>() {
            /* class com.androidx.p013lv.mine.activity.SettingActivity.C12693 */

            public void onChanged(BaseRes<VersionBean> baseRes) {
                if (SettingActivity.this.dialog != null) {
                    SettingActivity.this.dialog.dismiss();
                }
                if (baseRes.getCode() != 200 || baseRes.getData() == null) {
                    ToastUtils.getInstance().showWrong(UiUtils.getString(C1207R.string.hit_no_net));
                    return;
                }
                SettingActivity.this.versionBean = baseRes.getData();
                SettingActivity settingActivity = SettingActivity.this;
                settingActivity.versionUpdateProcessing(settingActivity.versionBean);
            }
        });
        this.model.getDownLoadData().observe(this, new Observer<DownLoadBean>() {
            /* class com.androidx.p013lv.mine.activity.SettingActivity.C12704 */

            public void onChanged(DownLoadBean downLoadBean) {
                SettingActivity.this.versionUpdateUI(downLoadBean);
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void versionUpdateProcessing(VersionBean versionBean2) {
        if (TextUtils.isEmpty(versionBean2.getVersionNum())) {
            ToastUtils.getInstance().showCorrect("已是最新版本");
            return;
        }
        try {
            if (Integer.parseInt(PackageUtils.getVersionName(getActivity()).replace(Consts.DOT, "")) >= Integer.parseInt(versionBean2.getVersionNum().replace(Consts.DOT, ""))) {
                ToastUtils.getInstance().showCorrect("已是最新版本");
                return;
            }
            this.downLoadUrl = versionBean2.getLink();
            DialogUpdate dialogUpdate2 = new DialogUpdate(this, ExifInterface.GPS_MEASUREMENT_INTERRUPTED + versionBean2.getVersionNum(), versionBean2.getInfo(), versionBean2.getLink(), false, this);
            this.dialogUpdate = dialogUpdate2;
            dialogUpdate2.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override // com.androidx.p013lv.mine.dialog.DialogUpdate.VersionUpdateInterface
    public void onConfirmClick() {
        if (TextUtils.isEmpty(this.downLoadUrl)) {
            this.dialogUpdate.dismiss();
            ToastUtils.getInstance().showWeak("無效下載鏈接");
        } else if (this.downLoadUrl.startsWith("http")) {
            this.model.doDownLoadFile(this.downLoadUrl);
        } else {
            this.dialogUpdate.dismiss();
            ToastUtils.getInstance().showWeak("下載鏈接非法");
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void versionUpdateUI(DownLoadBean downLoadBean) {
        if (downLoadBean != null && this.dialogUpdate != null) {
            if (downLoadBean.getCode() == 0) {
                this.dialogUpdate.startDownLoad();
                return;
            }
            Progress progress = downLoadBean.getProgress();
            if (downLoadBean.getCode() == 1) {
                this.dialogUpdate.setProgressState(progress);
            } else if (downLoadBean.getCode() == 2) {
                this.dialogUpdate.dismiss();
                ToastUtils.getInstance().showWrong(UiUtils.getString(C1207R.string.hit_no_net));
            } else if (downLoadBean.getCode() == 3) {
                File file = downLoadBean.getFile();
                this.dialogUpdate.dismiss();
                Context activity = getActivity();
                if (activity != null) {
                    DownloadFileUtils.openFile(activity, file);
                }
            }
        }
    }

    /* renamed from: com.androidx.lv.mine.activity.SettingActivity$OnClick */
    public class OnClick {
        public OnClick() {
        }

        public void btnBack() {
            SettingActivity.this.finish();
        }

        public void bindingPhone() {
            if (!SettingActivity.this.isOnClick()) {
                int i = 2;
                if (!TextUtils.isEmpty(SettingActivity.this.userInfo.getMobile())) {
                    i = 3;
                }
                ARouter.getInstance().build(Constance.LOGIN_ACTIVITY).withInt("type", i).navigation();
            }
        }

        public void exchangeVip() {
            if (!SettingActivity.this.isOnClick()) {
                ARouter.getInstance().build(Constance.EXCHANGE_CENTER_ACTIVITY).navigation();
            }
        }

        public void clearCatch() {
            if (!SettingActivity.this.isOnClick()) {
                DataCleanManager.clearAllCache(SettingActivity.this);
                GlideUtils.clear();
                ((ActivitySettingLayoutBinding) SettingActivity.this.binding).setCacheSize("0M");
                ToastUtils.getInstance().showCorrect("清理成功。");
            }
        }

        public void updateVersion() {
            if (SettingActivity.this.dialog == null) {
                SettingActivity.this.dialog = new DialogLoading(SettingActivity.this.getActivity());
            }
            SettingActivity.this.dialog.show();
            SettingActivity.this.model.checkLatestVersion();
        }

        public void changeAccount() {
            if (!SettingActivity.this.isOnClick()) {
                ARouter.getInstance().build(Constance.LOGIN_ACTIVITY).withInt("type", 1).navigation();
            }
        }

        public void accCredentialsBtn() {
            if (!SettingActivity.this.isOnClick()) {
                ARouter.getInstance().build(Constance.ACC_CREDENTIAL_ACTIVITY).withString(Key.TITLE, "設置").navigation();
            }
        }

        public void retrieveAccBtn() {
            if (!SettingActivity.this.isOnClick()) {
                ARouter.getInstance().build(Constance.RECOVER_ACC_ACTIVITY).navigation();
            }
        }

        public void contactOfficial() {
            if (!SettingActivity.this.isOnClick()) {
                ARouter.getInstance().build(Constance.CONTACT_OFFICIAL_ACTIVITY).navigation();
            }
        }
    }

    /* access modifiers changed from: protected */
    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, com.androidx.p013lv.base.p015ui.BaseActivity
    public void onDestroy() {
        CompositeDisposable compositeDisposable2 = this.compositeDisposable;
        if (compositeDisposable2 != null) {
            compositeDisposable2.dispose();
        }
        this.compositeDisposable = null;
        super.onDestroy();
    }
}
